<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>子页面</title>
    <script type="text/javascript" src="message.js"></script>
</head>
<body>
    <h1>子页面</h1>
    <button type="button" onclick="sendMsg()">发送消息到父页面</button>
</body>
<script type="text/javascript">
    function sendMsg(){
        var randomColor = "#" + getRandomColor();
        document.getElementsByTagName("h1")[0].style.color = randomColor;
        sendMessage("color", randomColor, "parent");
        sendMessage("msg", "Hello H5", "parent");
    }
    //随机颜色，十六进制方法；
    function getRandomColor( ) {
        var rand = Math.floor(Math.random( ) * 0xFFFFFF).toString(16);
        if(rand.length == 6){
            return rand;
        }else{
            return getRandomColor();
        }
    }
</script>
</html>